﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;

namespace baseClass.controls
{
    public partial class emRelativeDetail : common.control.baseUserControl
    {
        private BindingSource myDataSource = null;
        public emRelativeDetail()
        {
            InitializeComponent();
            relativeCodeNoteLbl.ForeColor = common.settings.sysColorHiLightFG;
            SetMaxLength();
        }

        public void SetDataSource(System.Windows.Forms.BindingSource dataSrc)
        {
            this.myDataSource = dataSrc;
            data.baseDS.emRelativesDataTable tbl = (data.baseDS.emRelativesDataTable)dataSrc.DataSource;
            this.familyRelaTypeCb.DataBindings.Clear();
            this.familyRelaTypeCb.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", dataSrc, tbl.relationTypeColumn.ColumnName, true));

            this.relativeCodeEd.DataBindings.Clear();
            this.relativeCodeEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", dataSrc, tbl.relativeCodeColumn.ColumnName, true));

            this.fulllNameEd.DataBindings.Clear();
            this.fulllNameEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", dataSrc, tbl.fullNameColumn.ColumnName, true));

            this.addressEd.DataBindings.Clear();
            this.addressEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", dataSrc, tbl.addressColumn.ColumnName, true));
        }
        private void SetMaxLength()
        {
            data.baseDS.emEducationDataTable tbl = new data.baseDS.emEducationDataTable();
            fulllNameEd.MaxLength = tbl.schoolNameColumn.MaxLength;
            addressEd.MaxLength = tbl.notesColumn.MaxLength;
        }
        public virtual void Init() 
        {
            familyRelaTypeCb.LoadData();
        }

        public virtual bool CheckData()
        {
            if (this.myDataSource.Current == null) return true;
            bool retVal = true;
            ClearNotifyError();
            if (fulllNameEd.Text.Trim() == "") 
            {
                NotifyError(fulllNameLbl);
                retVal = false;
            }
            if (familyRelaTypeCb.myValue == "")
            {
                NotifyError(relativeTypeLbl);
                retVal = false;
            }
            return retVal;
        }
        public virtual void LockEdit(bool state)
        {
            if (myDataSource.Current == null) state = true; 
            relativeCodeEd.ReadOnly = state;
            fulllNameEd.ReadOnly = state;
            familyRelaTypeCb.Enabled = !state;
            addressEd.ReadOnly = state;
        }
        public virtual void SetFocus()
        {
            this.Focus();
            familyRelaTypeCb.Focus();
        }
    }
}
